﻿/*******************************************************************************
 * Copyright © 2017 FriendStar.Framework 版权所有
 * Author: HYF
 * Description: FriendStar快速开发平台
 * Website：http://www.FriendStar.cn
*********************************************************************************/
using FriendStar.Application.SystemManage;
using FriendStar.Application.MainData;
using FriendStar.Code;
using FriendStar.Domain.Entity.MainData;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;

namespace FriendStar.Web.Areas.MainData.Controllers
{
    public class ItemsDataController : ControllerBase
    {
        BUS_SJ_DictionaryApp bus_sj_dictionaryApp = new BUS_SJ_DictionaryApp();

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetGridJson(string itemId, string keyword)
        {
            var data = bus_sj_dictionaryApp.GetList(itemId, keyword);
            return Content(data.ToJson());
        }
        //[HttpGet]
        //[HandlerAjaxOnly]
        //public ActionResult GetSelectJson(string enCode)
        //{
        //    var data = itemsDetailApp.GetItemList(enCode);
        //    var data = bus_sj_dictionaryApp.GetItemList(enCode);
        //    List<object> list = new List<object>();
        //    foreach (ItemsDetailEntity item in data)
        //    {
        //        list.Add(new { id = item.F_ItemCode, text = item.F_ItemName });
        //    }
        //    return Content(list.ToJson());
        //}
        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetFormJson(string keyValue)
        {
            var data = bus_sj_dictionaryApp.GetForm(keyValue);
            return Content(data.ToJson());
        }
        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitForm(BUS_SJ_DictionaryEntity entity, string keyValue)
        {
            if (bus_sj_dictionaryApp.CheckedEntity(entity))
            {
                bus_sj_dictionaryApp.SubmitForm(entity, keyValue);
                return Success("操作成功。");
            }
            else
            {
                return Error("操作失败，已经存在相同字典编号。");
            }
        }
        [HttpPost]
        [HandlerAjaxOnly]
        [HandlerAuthorize]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteForm(string keyValue)
        {
            bus_sj_dictionaryApp.DeleteForm(keyValue);
            return Success("删除成功。");
        }
    }
}
